#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : xuexiaohua
# @time    : 2025/8/20 18:38
# @function: the script is used to do something.
# @version :
import pymysql

from wework.utils.LogUtils import logger


class MysqlUtils:

    @classmethod
    def query_db(cls, sql, database_info):
        '''
        查询数据库
        :param sql: 要执行的sql语句
        :param database_info: 数据库的连接信息
        :return:
        '''
        # 连接数据库
        conn = pymysql.connect(**database_info)
        # 创建游标
        cursor = conn.cursor()
        # 执行sql语句
        cursor.execute(sql)
        # 获取查询结果
        result = cursor.fetchall()
        logger.info(f"数据库查询结果为：{result}")
        # 关闭游标
        cursor.close()
        # 关闭数据库
        conn.close()
        # 返回查询结果
        return result

